import { Public } from '@/common/decorator/public.decorator';
import { Body, Controller, Delete, Get, Post, Req } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { AuthService } from './auth.service';
import { LoginDto } from './dto/login.dto';

@Controller('auth')
@ApiTags('登录鉴权')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @Get('captcha')
  @ApiOperation({ summary: '获取验证码' })
  @Public()
  getCaptcha(@Req() req: any) {
    return req.captcha;
  }

  // @Post('login')
  // @ApiOperation({ summary: '用户登录' })
  // @Public()
  // @UseInterceptors(FileInterceptor('file')) // 文件拦截器，可以解析FormData格式数据，且body排除文件字段
  // login(@Body() body: LoginDto) {
  //   return this.authService.login(body);
  // }

  @Post('login')
  @ApiOperation({ summary: '用户登录(multer解析FormData)' })
  @Public()
  login(@Body() body: LoginDto) {
    console.log(body);
    return this.authService.login(body);
  }

  @Post('logup')
  @ApiOperation({ summary: '用户注册' })
  logup() {
    // TODO: 实现用户注册逻辑
  }

  @Delete('logout')
  @ApiOperation({ summary: '退出登录' })
  logout() {
    return this.authService.logout();
  }
}
